package com.timothy.junk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.HashMap;
import java.util.List;

import com.sina.util.StringUtil;
import com.timothy.junk.R;
import com.timothy.gfund.bean.Repo;

public class RepoAdaptor extends BaseAdapter {
	private Context 					mContext;
	private List<Repo> 				    listItems;
	private LayoutInflater 				mInflater;

	HashMap<Integer,View> viewMap = new HashMap<Integer,View>();

	static class ViewHolder{
	        public TextView index;
	        public TextView code;
		    public TextView name;
		    public TextView price;
	 }

	public RepoAdaptor(Context context, List<Repo> data) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context); 
		this.listItems = data;
	}

	
	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;  
        if (convertView == null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.repo_list_item, null);
            
			holder.index = (TextView) convertView.findViewById(R.id.index);
			holder.code = (TextView) convertView.findViewById(R.id.code);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.price = (TextView) convertView.findViewById(R.id.price);

            convertView.setTag(holder);  
        }else {  
            holder = (ViewHolder) convertView.getTag();  
        }

        Repo repo = listItems.get(position);
		
		holder.index.setText(String.valueOf(repo.getIndex()));
		holder.code.setText(repo.getCode());
		holder.name.setText(repo.getName());
		holder.price.setText(StringUtil.formatData2Deci(repo.getPrice())+"%");
		
        return convertView; 
        
	}

}
